package com.example.librarysystem.Service;

import com.example.librarysystem.Dao.BookManagementDao;
import com.example.librarysystem.entity.BookManagement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("bookManagementService")
public class BookManagementServiceImpl implements BookManagementService{
    @Autowired
    private BookManagementDao bookManagementDao;

    @Override
    public Integer selectCount(){
        return bookManagementDao.selectCount();
    }

    @Override
    @Transactional(timeout = 30)
    public int insertBookM(BookManagement bookManagement){
        bookManagementDao.insertBookM(bookManagement);
        return 0;
    }

    @Override
    public List<BookManagement> selectAllPage(int currentPage, int pageSize){
        if(currentPage<=0){
            return null;
        }
        int startCurrentPage=(currentPage-1)*pageSize;        //从第几个数据开始
        int count=selectCount();
        int totalPage=count/pageSize+1;                   //总页数
        if (currentPage>totalPage){
            return null;
        }else{
            return bookManagementDao.selectAllPage(startCurrentPage,pageSize);
        }
    }
}
